<template>
  <el-container>
    <el-header>
      <div>
        <img src="../assets/1.jpg" alt="" />
        <span>电商管理后台</span>
      </div>
      <el-button
        @click="loginout"
        type="info"
        icon="el-icon-switch-button"
        circle
      ></el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapes ? '64px' :'250px'">
        <div class="toggle" @click="toggleopen">
          |||
        </div>
        <el-menu
          unique-opened
          background-color="#333744"
          text-color="#fff"
          active-text-color="#4090ff"
          :collapse="isCollapes"
          :collapse-transition="false"
          router
          :default-active="activePath"
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <template slot="title">
              <i :class="icon[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
              :index="'/'+subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
              @click="saveNav('/'+subItem.path)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ subItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
      icon: {
        "125": "el-icon-user-solid",
        "103": "el-icon-lock",
        "101": "el-icon-s-cooperation",
        "102": "el-icon-s-order",
        "145": "el-icon-s-claim",
      },
      isCollapes:false,
      activePath:''
    };
  },
  created() {
    this.getMenuList();
    this.activePath=window.sessionStorage.getItem('activePath')
  },
  methods: {
    loginout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getMenuList() {
      var { data: res } = await this.$http.get("menus");
      this.menulist = res.data;
      console.log(res);
    },
    toggleopen(){
         this.isCollapes=!this.isCollapes
    },
    saveNav(activePath){
       window.sessionStorage.setItem('activePath',activePath)
       this.activePath=activePath
    }
  },
};
</script>

<style lang="less" scoped>
.el-container {
  width: 100%;
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-header img {
  margin-left: 20px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
}
.el-aside {
  background-color: #333744;
  
}
.el-main {
  background-color: #eaedf1;
}
.el-menu {
  border-right: none;
}
.toggle{
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 3px;
  cursor: pointer;
}
</style>
